package com.open.center.common.constant;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.springframework.util.StringUtils;

/**
 * 常量
 *
 * @author Riche's
 * @since 2025/5/23
 */
public class OpenConstant {

    private OpenConstant() {

    }

    public static final String DATE_FORMAT = "yyyy-MM-dd";

    public static final String TIME_FORMAT = "HH:mm:ss";

    public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";


    public static final String ROOT_ORGANIZATION_ID = "0";


    public static final String AUTHORIZATION = "Authorization";

    /**
     * 解析Header的Authorization认证Token
     */
    public static Optional<String> resolveToken(String authorizationToken) {
        if (StringUtils.hasText(authorizationToken)) {
            String token = authorizationToken.replaceFirst("Bearer ", "");
            if (StringUtils.hasText(token)) {
                return Optional.of(token);
            }
        }
        return Optional.empty();
    }


    public static <T> List<T> castList(Object obj, Class<T> clazz) {
        List<T> list = new ArrayList<>();
        if (obj instanceof List<?>) {
            for (Object o : (List<?>) obj) {
                list.add(clazz.cast(o));
            }
            return list;
        }
        return List.of();
    }

}
